package com.soda.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.soda.bean.Contact;
import com.soda.bean.Survey;
import com.soda.service.ContactService;
import com.soda.service.impl.ContactServiceImpl;

public class ContactServlet extends HttpServlet {
	
	ContactService cs=new ContactServiceImpl();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
 

		String param = request.getParameter("param");// 获得参数，由参数判断执行方法
		if (param != null) {
			// 查看
			if ("contact".equals(param)) {

				contact(request, response);
			}
			if ("update".equals(param)) {

				update(request, response);
			}
		
	}
	}

	
	private void update(HttpServletRequest request, HttpServletResponse response) {

		String phone=request.getParameter("phone");
		String neirong=request.getParameter("neirong");
		int num=cs.update(phone,neirong);
		if(num>0){
			contact(request, response);
		}
	}


	private void contact(HttpServletRequest request,
			HttpServletResponse response) {
	
		Contact ct=cs.contact();
		request.setAttribute("contact", ct);
		try {
			request.getRequestDispatcher("houtai/pages/publicityManage/onePageManage/relationUs.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
